﻿using System;
using System.Collections.Generic;
using System.Text;

using System.IO;
using System.Runtime;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Ipc;
using System.Security.Permissions;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Messaging;

using RemoteInteractiveForum.Domain;

using ForumServerIpcObjects;

namespace ForumClientProject
{
    class Client
    {
        [SecurityPermission(SecurityAction.Demand)]
        static void Main(string[] args)
        {
            Console.WriteLine("IPC Client\n");

            // Create the ipc channel
            IpcChannel ipcClientChannel = new IpcChannel();
            
            // Register the channel
            WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(
                typeof(InteractiveForum),
                "ipc://localhost:9090/InteractiveForum");
            RemotingConfiguration.RegisterWellKnownClientType(remoteType);

            // create a message sink
            string objectUri;
            IMessageSink msgSink = ipcClientChannel.CreateMessageSink("ipc://localhost:9090/InteractiveForum", null, out objectUri);
            if (msgSink != null)
            {
                Console.WriteLine("Type of message sink is {0}", msgSink.ToString());
            }
            // now create an instance of the remote object
            InteractiveForum svrObjectInterForum = new InteractiveForum();
            // and call its method
            svrObjectInterForum.addForum("nir_amar");
            Console.WriteLine(svrObjectInterForum.getForum(0).Name);

            Console.WriteLine();
            // Wait for the user input.
            Console.WriteLine("Type any key to exit IPC Client");
            Console.ReadKey();
        }
    }
}

